#include <stdio.h>                                                                                                                                                                                           
   
#include "color.h"
//#include "judgement.h"
//#include "guest_number.h"
#include "struct.h"
/*number_guest1 function is the game of the first mode, number_guest2 function is the game of the second mode
  storage_a_num and storage_b_num are the variable quantities to storage the input numbers, parameter function
  is to judge the number input.
  */
  int number_guest1(num_t *num)
{
	num->storage_a = 1;
	num->storage_b = 1000;

	printf(YELLOW_COLOR"请输入所猜的数字，在1--1000之间"RESET_COLOR"\n"); 

	parameter(num);
			  
	while (num->random != num->input) {
		if (num->input > num->storage_a && num->input < num->random) {
			printf(PURPLE_COLOR"你所猜的数字太小了,"
			       "在 %d 到 %d之间\n "
			        "请输入另一个数字!"RESET_COLOR"\n",num->input, num->storage_b);
			num->storage_a = num->input;
		} 
				              
		else if (num->random < num->input && num->input < num->storage_b) {
			printf(PURPLE_COLOR"你所猜的数字太大了,"
				"在 %d 到 %d 之间"
				"请输入另一个数字!"RESET_COLOR"\n",num->storage_a, num->input);
			num->storage_b = num->input;
		}
		else {
			printf(PURPLE_COLOR"在%d 到%d 之间"
				"请输入另一个数字"RESET_COLOR"\n",num->storage_a, num->storage_b);
		}
					     
		parameter(num);
	}
	printf(GREEN_COLOR"智商在线!恭喜你猜对啦！\n 李总裁奖励你一张黑卡，随便刷！\n再来一局"RESET_COLOR"\n");
		        
	return 0;
}
		   
 /*input[] and random[] are use to storage the remainders, input_digit and random_digit are the
  digits for input_num and random_num.
*/
		       
int number_guest2(num_t *num) 
{
	int input[3];
	int random[3];
	int input_digit;
	int random_digit;
	int count_1;
	int count_2;
	int count_right;
	int storage_num = num->random;
				  
	printf(YELLOW_COLOR"请输入所猜的数字，在1--1000之间"RESET_COLOR"\n");
				    
	parameter(num);
				     
	while (1) {
		count_right = 0;
		count_1 = 0;
		count_2 = 0;
		input_digit = 0;
		random_digit = 0;
		num->random = storage_num;
					     
		if (num->random == num->input)
			break;
					         
		for (count_1 = 0; num->random > 0; random_digit++) {
			random[count_1] = num->random % 10;
			num->random = num->random /10;
			count_1++;
		}
			  
		printf(YELLOW_COLOR"系统随机数是%d位数"RESET_COLOR"\n",random_digit);
			     
		for (count_2 = 0; num->input > 0; input_digit++) {
			input[count_2] = num->input % 10;
			num->input = num->input / 10;
			count_2++;
		}
		
				   
		for (count_1 = 0; count_1 < input_digit; count_1++) {
			for (count_2 = 0; count_2 < random_digit; count_2++) {
				if (input[count_1] == random[count_2]){ 
				      count_right++;
				      break;
				}
			continue;
		if (count_1==input_digit)
			break;
		}
	}
					     
		printf(YELLOW_COLOR"与系统随机数相同的个数有%d个\n"
			"请重新输入数字"RESET_COLOR"\n",count_right);
		parameter(num);
		
	}

	printf(GREEN_COLOR"恭喜你猜对啦！\n李总裁另有新欢，你来的太晚啦！\n再来一局\n"RESET_COLOR"\n");
					
	return 0;
	
}

